{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "00f1d67d-fa17-4417-8ba9-57c83342b6c9",
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "import os.path as osp\n",
    "from lxml import etree\n",
    "from selenium import webdriver\n",
    "import time\n",
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "71aa8cd0-6430-48f7-b172-313defabdd4d",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "path = r'D:\\Hresource\\SpiderPic'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "66a5d125-852b-4e53-abbf-a76aa5a9e66f",
   "metadata": {},
   "outputs": [],
   "source": [
    "broser= webdriver.Edge()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "e9bfe66a-8121-4b10-a253-9a2ea75652d2",
   "metadata": {},
   "outputs": [],
   "source": [
    "target_raw_url = 'https://www.fulitu.cc/page/{}'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "efa921c2-5967-4904-8970-85174ec29700",
   "metadata": {},
   "outputs": [],
   "source": [
    "for page in range(1, 75):\n",
    "    req = requests.get(target_raw_url.format(page))\n",
    "    html = etree.HTML((req.text))\n",
    "    href = html.xpath('//a[@class=\"item-link\"]/@href')\n",
    "    for i in href:\n",
    "        broser.get(i)\n",
    "        img_list = [url.get_attribute('src') for url in broser.find_elements('xpath', '//img[@class=\"post-item-img lazy\"]')]\n",
    "        if len(img_list) > 0:\n",
    "            for imgs in img_list:\n",
    "                name = str(int(time.time() * 1000))\n",
    "                name = osp.join(path, name + '.jpg')\n",
    "                with open(name, 'wb') as fp:\n",
    "                    fp.write(requests.get(imgs).content)\n",
    "                    fp.close()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
